package com.example.administrator.newsapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.newsapp.pojo.JokeData;

import java.util.List;

/**
 * ClassName:
 * Description:
 */

public class JokeListAdapter extends BaseAdapter {
    private Context mContext;
    private List<JokeData.ShowapiResBodyBean.ContentlistBean> contentlist;
    public JokeListAdapter(Context context, List<JokeData.ShowapiResBodyBean.ContentlistBean> contentlist) {
        mContext = context;
        this.contentlist = contentlist;
    }

    @Override
    public int getCount() {
        return contentlist.size();
    }

    @Override
    public Object getItem(int position) {
        return contentlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.joke_list_item,parent,false);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.tvTitle=convertView.findViewById(R.id.list_item_title);
            viewHolder.tvContent=convertView.findViewById(R.id.list_view_content);
            viewHolder.ivImage = convertView.findViewById(R.id.list_item_iv);
            viewHolder.tvTime=convertView.findViewById(R.id.list_item_time);
            convertView.setTag(viewHolder);
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        JokeData.ShowapiResBodyBean.ContentlistBean  contentlistBean = contentlist.get(position);
        holder.tvTitle.setText(position+1+"、"+contentlistBean.getTitle());
        holder.tvContent.setText(contentlistBean.getText());
        holder.tvTime.setText(contentlistBean.getCt());
        Glide.with(mContext).load(contentlistBean.getImg()).into(holder.ivImage);


        return convertView;
    }
    class ViewHolder{
        private TextView tvTitle;
        private TextView tvContent;
        private ImageView ivImage;
        private TextView tvTime;
    }
}
